import React, { Component } from "react";
import PropTypes from 'prop-types';
import { saveFormData, saveImg, clearData } from '../store/home/action';
import { connect } from 'react-redux'
import Http from '../http/config'
import Api from '../http/api'
import HomeComponent from '../components/Home'
class Connect extends React.Component{
    static propTypes = {
        formData: PropTypes.object.isRequired,
        saveFormData: PropTypes.func.isRequired,
        saveImg: PropTypes.func.isRequired,
        clearData: PropTypes.func.isRequired,
    }
    componentWillMount(){
        let obj = {
            noHttpLoading: false,
            params: {
                phone:"",
                pwd:"",
            }
        };
        Http.post(Api.login.login, obj).then((res) => {
            console.log(res)
        }).catch((err)=>{
            console.log(err)
        })
        this.setState({myUserName:"12345464"})

    }
    onChange = (e) => {
        this.props.saveFormData(e.target.value,"name");
    }
    onClick = (e) => {
        this.props.saveFormData(this.props.formData.orderSum+1,"orderSum");
    }
    handleForm(){
        console.log(1)
    }
    render(){
        return (
            <div>
                <div>state:{this.state.myUserName}</div>
                <div>dasdasdasdas</div>
                <p>user: {this.props.formData.name}, orderSum: {this.props.formData.orderSum}</p>
                user:
                <input type="text" className="input" name="name" onChange={this.onChange}/>
                &nbsp;

                <button className="btn" onClick={this.onClick}>年龄增长</button>
                <div>
                      <HomeComponent clickForm={this.handleForm} />
                    12313
                </div>

            </div>

        );
    }
}

export default connect(store => ({
    formData:store.homeData
}),{saveFormData, saveImg, clearData})(Connect);


